﻿<%@ Page Language="VB" 
  MasterPageFile="~/MasterAccounts.master" 
  AutoEventWireup="false" 
  CodeFile="Acct_Aankoop.aspx.vb" 
  Inherits="Acct_Aankoop" 
  title="Aankoop Dagboek" %>


<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder" Id="InvList" >
  <script language="javascript" type="text/javascript" >
    // Yves Pattyn
    // 25/01/2011
    // Net Amount correction in case transport is given.
    //
    function ReCalcNet() {
      if (!document.getElementById) {
        alert("getElementById not supported.");
        return false;
      }
      var txtTransport = document.getElementById("ctl00_ContentPlaceHolder_txtTransportAmount");
      var p = parseFloat(txtTransport["value"]);
      var txtNet1 = document.getElementById("ctl00_ContentPlaceHolder_txtNetAmount1");
      var n1 = parseFloat(txtNet1["value"]);
      var txtNet2 = document.getElementById("ctl00_ContentPlaceHolder_txtNetAmount2");
      var n2 = parseFloat(txtNet2["value"]);
      var txtNet3 = document.getElementById("ctl00_ContentPlaceHolder_txtNetAmount3");
      var n3 = parseFloat(txtNet3["value"]);
      var txtVat = document.getElementById("ctl00_ContentPlaceHolder_txtVatAmount");
      var v = parseFloat(txtVat["value"]);
      var txtVatRate = document.getElementById("ctl00_ContentPlaceHolder_txtVatRate");
      var vr = parseFloat(txtVat["value"]);
      var txtTot = document.getElementById("ctl00_ContentPlaceHolder_txtTotalAmount");
      var t = parseFloat(txtTot["value"]);
      var txtTotD = document.getElementById("ctl00_ContentPlaceHolder_txtTotalDebit");
      var txtTotC = document.getElementById("ctl00_ContentPlaceHolder_txtTotalCredit");
      n1 = (t - (v + p + n2 + n3));
      txtNet1["value"] = n1.toFixed(2);
      txtTotD["value"] = t.toFixed(2);
      txtTotC["value"] = (v + p + n1 + n2 + n3).toFixed(2);
      return false;
    }
    function ReCalcVat() {
      if (!document.getElementById) {
        alert("getElementById not supported.");
        return false;
      }
      var txtTransport = document.getElementById("ctl00_ContentPlaceHolder_txtTransportAmount");
      var txtNet1 = document.getElementById("ctl00_ContentPlaceHolder_txtNetAmount1");
      var txtNet2 = document.getElementById("ctl00_ContentPlaceHolder_txtNetAmount2");
      var txtNet3 = document.getElementById("ctl00_ContentPlaceHolder_txtNetAmount3");
      var txtVat = document.getElementById("ctl00_ContentPlaceHolder_txtVatAmount");
      var txtVatRate = document.getElementById("ctl00_ContentPlaceHolder_txtVatRate");
      var vr = parseFloat(txtVatRate["value"]);
      var txtTot = document.getElementById("ctl00_ContentPlaceHolder_txtTotalAmount");
      var t = parseFloat(txtTot["value"]);
      vr = vr / 100.0;
      txtNet1["value"] = (t * (1 - vr)).toFixed(2);
      txtNet2["value"] = "0.00";
      txtNet3["value"] = "0.00";
      txtTransport["value"] = "0.00";
      txtVat["value"] = (vr * t / (1 + vr)).toFixed(2);
      return false;
    }
  </script>
  
  <table>
    <tr>
      <td valign="top">
        <table align="left" border="0" cellpadding="3">
          <tr>
            <td align="left" colspan="2" class="txtStyle">
              Nog te boeken aankoopfakturen.
            </td>
          </tr>
          <tr>
            <td>
              <asp:gridview id="grdInvoices" 
                HorizontalAlign="Left"
                datasourceid="dsInvoices" 
                DataKeyNames="InvNr"
                autogeneratecolumns="False"
                AutoGenerateSelectButton="true"
                emptydatatext="Geen openstaande fakturen voor deze leverancier." 
                allowpaging="true"
                runat="server" 
                AllowSorting="false" 
                AutoGenerateEditButton="false" 
                Caption="Invoices" 
                PagerSettings-PageButtonCount="30" 
                CellPadding="5" 
                ShowFooter="True" 
                style="margin-left: 0px; 
                margin-right: 4px">
                  <Columns>
                    <asp:HyperLinkField DataTextField="InvNr" HeaderText="Invoice Nr"
                      datanavigateurlfields="InvNr"
                      datanavigateurlformatstring="~\InvEdit.aspx?InvNr={0}"          
                      target="_blank"  />
                    <asp:BoundField DataField="InvDate" HeaderText="Invoice Date" ReadOnly="true" dataformatstring="{0:d}"/>
                    <asp:BoundField DataField="SupplierId" HeaderText="SupplierId" ReadOnly="true"/>
                    <asp:BoundField DataField="SupplierRef" HeaderText="Suppl. Ref." ReadOnly="true"/>
                    <asp:BoundField DataField="AmountNet" HeaderText="Net Amount" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"  dataformatstring="{0:N}"/>
                    <asp:BoundField DataField="AmountVAT" HeaderText="VAT" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" dataformatstring="{0:N}"/>
                    <asp:BoundField DataField="Currency" HeaderText="Currency" ReadOnly="true" />
                    <asp:BoundField DataField="AmountPaid" HeaderText="Paid" ReadOnly="true"  ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" dataformatstring="{0:N}"/>
                    <asp:BoundField DataField="DatePaid" HeaderText="on" ReadOnly="true"  dataformatstring="{0:d}"/>
                    <asp:BoundField DataField="Mark" HeaderText="mrk" ReadOnly="true"  />
                  </Columns>
              </asp:gridview>                
              <asp:AccessDataSource id="dsInvoices"
                selectcommand="Select * from Invoices 
                               where (InvDate between startDate and endDate) AND not InAccounts Order by InvDate ASC "
                runat="server" >
                <SelectParameters>
                  <asp:Parameter DbType="Date"  DefaultValue="01/09/2009" Name="startDate" />
                  <asp:Parameter DbType="Date"  DefaultValue="31/08/2010" Name="endDate" />
                </SelectParameters>
              </asp:AccessDataSource>
            </td>
          </tr>
        </table> 
      </td>
      <td valign="top">
        <table width="200">
          <th colspan="3" align="center" class="headerRowStyle">
            <b>Voorgestelde boekingen aankoop</b>
            <asp:Label runat="server" ID="lblDate" /><br />
            <asp:Label runat="server" ID="lblEuroRate" Visible="false" />
          </th>
          <tr>
            <td class="rowStyle" colspan="2">
              VAT Rate (%)
            </td>
            <td align="center"  class="rowStyle">
              <asp:TextBox runat="server" ID="txtVatRate" Text="0.00" onChange="ReCalcVat();"/>
            </td>
          </tr>
          <tr>
            <td class="rowStyle">
              Rekening
            </td>
            <td align="center"  class="rowStyle">
              Debet
            </td>
            <td align="center"  class="rowStyle">
              Credit
            </td>
          </tr>
          <tr>
            <td  class="rowStyle">
              <asp:DropDownList DataSourceId="dsSupplierAccts" runat="server" ID="lstSupplierAccounts"  
                DataValueField="AccountId" DataTextField="Description"/>
              <asp:AccessDataSource 
                ID="dsSupplierAccts" 
                runat="server" 
                SelectCommand="SELECT * from Acct_Accounts where AccountId between 410000 and 410999 Order by Description"
                DataFile="App_Data/2010Accountancy.mdb" />
            </td>
            <td align="right"  class="rowStyle">
              &nbsp;
            </td>
            <td align="right" class="rowStyle">
              <asp:Textbox runat="server" ID="txtTotalAmount"  />
            </td>
          </tr>
          <tr>
            <td class="rowStyle">
              <asp:DropDownList DataSourceId="dsAccounts1" runat="server" ID="lstContraAccount1"  
                DataValueField="AccountId" DataTextField="Description"/>
              <asp:AccessDataSource 
                ID="dsAccounts1" 
                runat="server" 
                SelectCommand="SELECT * from Acct_Accounts where AccountId between 600000 and 699999 Order by Description"
                DataFile="App_Data/2010Accountancy.mdb" />

            </td>
            <td align="right" class="rowStyle">
              <asp:TextBox runat="server" ID="txtNetAmount1"  Text="0.00" />
            </td>
            <td align="right" class="rowStyle">
              &nbsp;
            </td>
          </tr>


          <tr>
            <td class="rowStyle">
              <asp:DropDownList DataSourceId="dsAccounts2" runat="server" ID="lstContraAccount2"  
                DataValueField="AccountId" DataTextField="Description"/>
              <asp:AccessDataSource 
                ID="dsAccounts2" 
                runat="server" 
                SelectCommand="SELECT * from Acct_Accounts where AccountId between 600000 and 699999 Order by Description"
                DataFile="App_Data/2010Accountancy.mdb" />

            </td>
            <td align="right" class="rowStyle">
              <asp:TextBox runat="server" ID="txtNetAmount2" Text="0.00" onBlur="ReCalcNet();"/>
            </td>
            <td align="right" class="rowStyle">
              &nbsp;
            </td>
          </tr>
          <tr>
            <td class="rowStyle">
              <asp:DropDownList DataSourceId="dsAccounts3" runat="server" ID="lstContraAccount3"  
                DataValueField="AccountId" DataTextField="Description"/>
              <asp:AccessDataSource 
                ID="dsAccounts3" 
                runat="server" 
                SelectCommand="SELECT * from Acct_Accounts where AccountId between 600000 and 699999 Order by AccountId"
                DataFile="App_Data/2010Accountancy.mdb" />
            </td>
            <td align="right" class="rowStyle">
              <asp:TextBox runat="server" ID="txtNetAmount3" Text="0.00" onBlur="ReCalcNet();"/>
            </td>
            <td align="right" class="rowStyle">
              &nbsp;
            </td>
          </tr>



          <tr>
            <td class="rowStyle">
              VAT - Terug te vorderen
            </td>
            <td align="right" class="rowStyle">
              <asp:TextBox runat="server" ID="txtVatAmount"  Text="0.00" onBlur="ReCalcNet();"/>
            </td>
            <td align="right" class="rowStyle">
              &nbsp;
            </td>
          </tr>
          <tr>
            <td class="rowStyle">
              Transport Kosten
            </td>
            <td align="right" class="rowStyle">
              <asp:TextBox runat="server" ID="txtTransportAmount" Text="0.00" onBlur="ReCalcNet();"/>
            </td>
            <td align="right" class="rowStyle">
              &nbsp;
            </td>
          </tr>
          <tr>
            <td class="rowStyle">
              Totalen
            </td>
            <td align="right" class="rowStyle">
              <asp:TextBox runat="server" ID="txtTotalDebit" Enabled="false" />
            </td>
            <td align="right" class="rowStyle">
              <asp:TextBox runat="server" ID="txtTotalCredit" Enabled="false" />
            </td>
          </tr>
          <tr>
            <td class="rowStyle" colspan="3">
              <asp:Button runat="server" ID="btBookTransaction" Text="Ok, uitvoeren" />
            </td>
          </tr>
        </table>        
      </td>
    </tr>
  </table>
</asp:Content>
